﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    

    public partial class Form3 : Form
    {
        Form2 O;

        public Form3(Form2 F)
        {
            
            InitializeComponent();
            O = F;
            DataGridViewSelectedCellCollection s = F.dataGridView1.SelectedCells;
            if (s.Count < 1) this.Close();
            foreach (DataGridViewCell c in s)
            {
                label1.Text = F.r.GetInfo(0, c.ColumnIndex).ToString();
                label2.Text = O.r.GetInfo(c.RowIndex + 1, O.r.kolumny - 1).ToString();
                textBox1.Text = c.Value.ToString();
                if (O.r.GetInfo(0, c.ColumnIndex).ToString() == "Parafia") { textBox1.Text = "1"; label1.Text = "Parafia - wprowadź id"; }
                if (O.r.GetInfo(0, c.ColumnIndex).ToString() == "Miejsce_Pracy") { textBox1.Text = "1"; label1.Text = "Parafia pracy - wprowadź id"; }
            }
            

           
        }

        private void Form3_Load(object sender, EventArgs e)
        {

      
        }
        void edit1() {

            DataGridViewSelectedCellCollection s = O.dataGridView1.SelectedCells;
            if (s.Count < 1) return;
            string tab = O.nazwatabeli;
            if (tab == "ludziewszyscy") tab = "ludzie";
            foreach (DataGridViewCell c in s)
                if (O.r.GetInfo(0, c.ColumnIndex).ToString() == "Id") this.Close(); else BazaDaych.Wykonaj("Update " + tab + " set " + O.r.GetInfo(0, c.ColumnIndex).ToString() + "=" + "\'" + textBox1.Text + "\'" + " Where " + " id= " + O.r.GetInfo(c.RowIndex + 1, O.r.kolumny - 1).ToString() + ";");
            O.pokazwszystko();
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Form2.rodzaj(O.nazwatabeli) == 1) edit1();
            
        }
    }
}
